<?php

// TITLE: event
// FILE: event.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:54:38 PM
?>

		public function createEvent($id, $title, $date, $addressId, $typeId) {
			global $con;
			$sql = 'INSERT INTO event (id, title, date, address_id, type_id) VALUES (' . $id . ', ' . $title . ', ' . $date . ', ' . $addressId . ', ' . $typeId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readEvent($id) {
			global $con;
			$sql = 'SELECT * FROM event WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$event = new Event();
				$event->setId($result[0]);
				$event->setTitle($result[1]);
				$event->setDate($result[2]);
				$event->setAddressId($this->readAddress($result[3]));
				$event->setTypeId($this->readType($result[4]));
			} else {
				$event = false;
			}
			return $event;
		}// end function

		public function updateEvent($id, $title, $date, $addressId, $typeId) {
			global $con;
			$sql = 'UPDATE event SET title = ' . $title . ', date = ' . $date . ', address_id = ' . $addressId . ', type_id = ' . $typeId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteEvent($id) {
			global $con;
			$sql = 'DELETE FROM event WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listEvent() {
			global $con;
			$sql = 'SELECT * FROM event';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$events = array();
				while ($result = mysqli_fetch_array($results)) {
					$event = new Event();
					$event->setId($result[0]);
					$event->setTitle($result[1]);
					$event->setDate($result[2]);
					$event->setAddressId($this->readAddress($result[3]));
					$event->setTypeId($this->readType($result[4]));
					$events[] = $event;
				}// end while
			} else {
				$events = false;
			}
			return $events;
		}// end function

		// event_build // --------------------

		public function createEventBuild($eventId, $projectId) {
			global $con;
			$sql = 'INSERT INTO event_build (event_id, project_id) VALUES (' . $eventId . ', ' . $projectId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readEventBuild($id) {
			global $con;
			$sql = 'SELECT * FROM event_build WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$eventBuild = new EventBuild();
				$eventBuild->setEventId($this->readEvent($result[0]));
				$eventBuild->setProjectId($this->readProject($result[1]));
			} else {
				$eventBuild = false;
			}
			return $eventBuild;
		}// end function

		public function updateEventBuild($eventId, $projectId) {
			global $con;
			$sql = 'UPDATE event_build SET event_id = ' . $event_id . ', project_id = ' . $projectId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteEventBuild($id) {
			global $con;
			$sql = 'DELETE FROM event_build WHERE event_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listEventBuild() {
			global $con;
			$sql = 'SELECT * FROM event_build';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$eventBuilds = array();
				while ($result = mysqli_fetch_array($results)) {
					$eventBuild = new EventBuild();
					$eventBuild->setEventId($this->readEvent($result[0]));
					$eventBuild->setProjectId($this->readProject($result[1]));
					$eventBuilds[] = $eventBuild;
				}// end while
			} else {
				$eventBuilds = false;
			}
			return $eventBuilds;
		}// end function

		// event_detail // --------------------

		public function createEventDetail($id, $eventId, $title, $description, $interestId, $maxHeadCount, $hoursDuration) {
			global $con;
			$sql = 'INSERT INTO event_detail (id, event_id, title, description, interest_id, max_head_count, hours_duration) VALUES (' . $id . ', ' . $eventId . ', ' . $title . ', ' . $description . ', ' . $interestId . ', ' . $maxHeadCount . ', ' . $hoursDuration . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readEventDetail($id) {
			global $con;
			$sql = 'SELECT * FROM event_detail WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$eventDetail = new EventDetail();
				$eventDetail->setId($result[0]);
				$eventDetail->setEventId($this->readEvent($result[1]));
				$eventDetail->setTitle($result[2]);
				$eventDetail->setDescription($result[3]);
				$eventDetail->setInterestId($this->readInterest($result[4]));
				$eventDetail->setMaxHeadCount($result[5]);
				$eventDetail->setHoursDuration($result[6]);
			} else {
				$eventDetail = false;
			}
			return $eventDetail;
		}// end function

		public function updateEventDetail($id, $eventId, $title, $description, $interestId, $maxHeadCount, $hoursDuration) {
			global $con;
			$sql = 'UPDATE event_detail SET event_id = ' . $event_id . ', title = ' . $title . ', description = ' . $description . ', interest_id = ' . $interestId . ', max_head_count = ' . $maxHeadCount . ', hours_duration = ' . $hoursDuration . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteEventDetail($id) {
			global $con;
			$sql = 'DELETE FROM event_detail WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listEventDetail() {
			global $con;
			$sql = 'SELECT * FROM event_detail';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$eventDetails = array();
				while ($result = mysqli_fetch_array($results)) {
					$eventDetail = new EventDetail();
					$eventDetail->setId($result[0]);
					$eventDetail->setEventId($this->readEvent($result[1]));
					$eventDetail->setTitle($result[2]);
					$eventDetail->setDescription($result[3]);
					$eventDetail->setInterestId($this->readInterest($result[4]));
					$eventDetail->setMaxHeadCount($result[5]);
					$eventDetail->setHoursDuration($result[6]);
					$eventDetails[] = $eventDetail;
				}// end while
			} else {
				$eventDetails = false;
			}
			return $eventDetails;
		}// end function

		// event_expense // --------------------

		public function createEventExpense($id, $eventId, $title, $description, $amount, $whoEntered, $whenEntered, $whoAuthorized, $whenAuthorized) {
			global $con;
			$sql = 'INSERT INTO event_expense (id, event_id, title, description, amount, who_entered, when_entered, who_authorized, when_authorized) VALUES (' . $id . ', ' . $eventId . ', ' . $title . ', ' . $description . ', ' . $amount . ', ' . $whoEntered . ', ' . $whenEntered . ', ' . $whoAuthorized . ', ' . $whenAuthorized . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readEventExpense($id) {
			global $con;
			$sql = 'SELECT * FROM event_expense WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$eventExpense = new EventExpense();
				$eventExpense->setId($result[0]);
				$eventExpense->setEventId($this->readEvent($result[1]));
				$eventExpense->setTitle($result[2]);
				$eventExpense->setDescription($result[3]);
				$eventExpense->setAmount($result[4]);
				$eventExpense->setWhoEntered($result[5]);
				$eventExpense->setWhenEntered($result[6]);
				$eventExpense->setWhoAuthorized($result[7]);
				$eventExpense->setWhenAuthorized($result[8]);
			} else {
				$eventExpense = false;
			}
			return $eventExpense;
		}// end function

		public function updateEventExpense($id, $eventId, $title, $description, $amount, $whoEntered, $whenEntered, $whoAuthorized, $whenAuthorized) {
			global $con;
			$sql = 'UPDATE event_expense SET event_id = ' . $event_id . ', title = ' . $title . ', description = ' . $description . ', amount = ' . $amount . ', who_entered = ' . $whoEntered . ', when_entered = ' . $whenEntered . ', who_authorized = ' . $whoAuthorized . ', when_authorized = ' . $whenAuthorized . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteEventExpense($id) {
			global $con;
			$sql = 'DELETE FROM event_expense WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listEventExpense() {
			global $con;
			$sql = 'SELECT * FROM event_expense';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$eventExpenses = array();
				while ($result = mysqli_fetch_array($results)) {
					$eventExpense = new EventExpense();
					$eventExpense->setId($result[0]);
					$eventExpense->setEventId($this->readEvent($result[1]));
					$eventExpense->setTitle($result[2]);
					$eventExpense->setDescription($result[3]);
					$eventExpense->setAmount($result[4]);
					$eventExpense->setWhoEntered($result[5]);
					$eventExpense->setWhenEntered($result[6]);
					$eventExpense->setWhoAuthorized($result[7]);
					$eventExpense->setWhenAuthorized($result[8]);
					$eventExpenses[] = $eventExpense;
				}// end while
			} else {
				$eventExpenses = false;
			}
			return $eventExpenses;
		}// end function

		// event_type // --------------------

		public function createEventType($id, $title, $code, $description) {
			global $con;
			$sql = 'INSERT INTO event_type (id, title, code, description) VALUES (' . $id . ', ' . $title . ', ' . $code . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readEventType($id) {
			global $con;
			$sql = 'SELECT * FROM event_type WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$eventType = new EventType();
				$eventType->setId($result[0]);
				$eventType->setTitle($result[1]);
				$eventType->setCode($result[2]);
				$eventType->setDescription($result[3]);
			} else {
				$eventType = false;
			}
			return $eventType;
		}// end function

		public function updateEventType($id, $title, $code, $description) {
			global $con;
			$sql = 'UPDATE event_type SET title = ' . $title . ', code = ' . $code . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteEventType($id) {
			global $con;
			$sql = 'DELETE FROM event_type WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listEventType() {
			global $con;
			$sql = 'SELECT * FROM event_type';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$eventTypes = array();
				while ($result = mysqli_fetch_array($results)) {
					$eventType = new EventType();
					$eventType->setId($result[0]);
					$eventType->setTitle($result[1]);
					$eventType->setCode($result[2]);
					$eventType->setDescription($result[3]);
					$eventTypes[] = $eventType;
				}// end while
			} else {
				$eventTypes = false;
			}
			return $eventTypes;
		}// end function

		// for_project // --------------------

		public function createForProject($projectId, $donationId) {
			global $con;
			$sql = 'INSERT INTO for_project (project_id, donation_id) VALUES (' . $projectId . ', ' . $donationId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readForProject($id) {
			global $con;
			$sql = 'SELECT * FROM for_project WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$forProject = new ForProject();
				$forProject->setProjectId($this->readProject($result[0]));
				$forProject->setDonationId($this->readDonation($result[1]));
			} else {
				$forProject = false;
			}
			return $forProject;
		}// end function

		public function updateForProject($projectId, $donationId) {
			global $con;
			$sql = 'UPDATE for_project SET project_id = ' . $project_id . ', donation_id = ' . $donationId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteForProject($id) {
			global $con;
			$sql = 'DELETE FROM for_project WHERE project_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listForProject() {
			global $con;
			$sql = 'SELECT * FROM for_project';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$forProjects = array();
				while ($result = mysqli_fetch_array($results)) {
					$forProject = new ForProject();
					$forProject->setProjectId($this->readProject($result[0]));
					$forProject->setDonationId($this->readDonation($result[1]));
					$forProjects[] = $forProject;
				}// end while
			} else {
				$forProjects = false;
			}
			return $forProjects;
		}// end function

